var updated = false;
layui.use(function(){
	var upload = layui.upload;
	var layer = layui.layer;
	var element = layui.element;
	var $ = layui.$;
	// 单图片上传
	var uploadInst = upload.render({
		elem: '#upload-btn',
		url: '/editor/uploads?type=1', // 实际使用时改成您自己的上传接口即可。
		before: function(obj){
			// 预读本地文件示例，不支持ie8
			obj.preview(function(index, file, result){
				$('#upload-img').attr('src', result); // 图片链接（base64）
			});
		},
		done: function(obj){
			$('input[name=avatar]').val(obj.url);
			updated = true;
		}
	});
});
$('.layui-update').keyup(function(){
	updated = true;
});
$('.submit-btn').click(function() {
	if (updated)
	{
		var data = {}
		for (var i = $('.layui-update').length - 1; i >= 0; i--) {
			var name = $($('.layui-update')[i]).attr('name');
			var value = $($('.layui-update')[i]).val();
			if (name && name != 'undefined') data[name] = value;
		}
		$.ajax({
			data: data,
			type: 'post',
			url: '/profile/update',
			success:function(obj){
				layer.msg(obj.msg);
			}
		});
	}else{
		layer.msg('没有任何值发生改变');
	}
})